package list_Node;
//160. 相交链表
public class Num160_getIntersectionNode {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode pa=headA;
        ListNode pb=headB;
        while (pb!=pa){
            pa=pa==null?headB:pa.next;
            pb=pb==null?headA:pb.next;
        }
        return pa;


//        ListNode pA = headA;
//        ListNode pB = headB;
//        // 1.相交时刚好返回交点
//        // 2.不相交两个同时走到null
//        while (pA != pB) {
//            pA = pA == null ? headB : pA.next;
//            pB = pB == null ? headA : pB.next;
//        }
//        return pA;
    }

}
